package com.ynny.chapter13.mapper;




import com.ynny.chapter13.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface UserMapper {


    @Select("""

        select * from tb_user
        where username like concat('%' , #{username},'%')  

""")
    List<User> selectAll(String username);

    //Map用得更多
    @Select("""

            SELECT u.*,p.*
            FROM tb_user u
            LEFT JOIN tb_user_product up
            ON up.user_id = u.user_id
            LEFT JOIN tb_product p
            ON p.product_id = up.product_id

""")
    List<Map> selectAllUserAndProduct();


    @Insert("""
    insert into tb_user(username,password)
    values (#{username} , #{password} )

""")
    int insert(User user);

    @Update("""
    
    update tb_user set username = #{username} ,
    password = #{password} 
    where user_id = #{userId} 

""")
    int update(User user);

    @Delete("""

    delete from tb_user
    where user_id = #{userId} 
""")
    int delete(Integer userId);

}
